﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Input;

namespace Slex {
    public class Command : ICommand {
        public event Func<object, bool> CanExecuteContent;
        public bool CanExecute(object parameter) {
            if (this.CanExecuteContent != null) {
                return CanExecuteContent.Invoke(parameter);
            }
            return true;
        }
        public event EventHandler CanExecuteChanged;
        private readonly Action<object> executeAct;
        public void Execute(object parameter) {
            if (this.executeAct != null)
                this.executeAct.Invoke(parameter);
        }
        public Command(Action<object> ec) {
            this.executeAct = ec;
        }
        public static implicit operator Action<object>(Command cmd) {
            return cmd.executeAct;
        }
        public static implicit operator Command(Action<object> exe) {
            return new Command(exe);
        }
        public static implicit operator Command(Action exe) {
            Action<object> x = y => { exe.Invoke(); };
            return new Command(x);
        }
    }
}
